// pages/songs/songs.js
import {request} from '../../utils/request'
Page({

    /**
     * 页面的初始数据
     */
    data: {
      musicData:{},
      musicList:[]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: async function () {
      const eventChannel = this.getOpenerEventChannel()
      eventChannel.on('detail',({ musicData }) =>{
        this.setData({musicData})
      })
      let musicDataList = await request("/song/music","GET",{
        songId:this.data.musicData.id
      })
      this.setData({
        musicList:musicDataList.data
      })
    },
    toSongDetail(e){
      let index = e.currentTarget.dataset.index
      let currentMusic =  this.data.musicList[index]
      wx.navigateTo({
        url: '/pages/songDetail/songDetail',
        success: function(res) {
          res.eventChannel.emit('detail', { musicData:currentMusic})
        }
      })
  },
})